package com.example.myproject.common;

public class ResponseData<T> {
    private int code;        // 200 成功，其他为错误码
    private String message;  // 提示信息
    private T data;          // 返回业务数据

    public ResponseData() {}

    public ResponseData(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 成功且有数据
    public static <T> ResponseData<T> success(T data) {
        return new ResponseData<>(200, "success", data);
    }
    // 成功且无数据
    public static ResponseData<Void> success() {
        return new ResponseData<>(200, "success", null);
    }
    // 失败返回
    public static <T> ResponseData<T> fail(int code, String msg) {
        return new ResponseData<>(code, msg, null);
    }

    // getters & setters
    public int getCode() { return code; }
    public void setCode(int code) { this.code = code; }
    public String getMessage() { return message; }
    public void setMessage(String message) { this.message = message; }
    public T getData() { return data; }
    public void setData(T data) { this.data = data; }
}
